package com.lanhao.aot.carrierintegration.jiayou;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpRequest;

/**
 *  对接加拿大邮政
 * @author KunZhou
 */
public class JiaYouUtil {
	public static final String BASE_URL = "http://api.dev.ltianexp.com/v1";
//	public static final String BASE_URL = "https://api.otms.ltianexp.com/v1";
	public static final String CODE = "test";
	public static final String APIKEY = "1958538970ce46b79081437d8d3d35b4";
	public static final String ORDER_URL = "/api/orderNew/createOrder";
	
	public static void main(String[] args) {
		
		Map<String, String> header = new HashMap<>();
		header.put("code", CODE);
		header.put("apiKey", APIKEY);
		header.put("timestamp", DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN));
		header.put("sign", SecureUtil.md5(CODE + APIKEY));
		String request = "{\"channelCode\":\"CA002\",\"referenceNo\":\"CNO00001\",\"trackingNo\":\"\",\"productType\":1,\"pweight\":1,\"pieces\":1,\"insured\":0,\"batteryType\":\"1\",\"shipMode\":\"DDU\",\"consigneeName\":\"tom\",\"consigneeCompany\":\"tom company\",\"consigneeCountryCode\":\"CA\",\"consigneeProvince\":\"ON\",\"consigneeCity\":\"Waterloo\",\"consigneeDistrict\":\"\",\"consigneeStreet\":\"Qinghu Jiedao\",\"consigneeHouseNumber\":\"Donnelly Logistics Park A209\",\"consigneeAddress\":\"2606 Lobsinger Line RR#1\",\"consigneePostcode\":\"N2J4G8\",\"consigneeMobile\":\"18888888888\",\"consigneePhone\":\"6472789204\",\"consigneeEmail\":\"88888@qq.com\",\"consigneePassport\":\"\",\"consigneeWarehouse\":\"\",\"consigneeTariff\":\"9988988988\",\"shipperName\":\"zhangsan\",\"shipperCompany\":\"letian guoji\",\"shipperCountryCode\":\"CN\",\" shipperProvince\":\"gudangdong\",\"shipperCity\":\"shenzheng\",\"shipperDistrict\":\"longhua\",\"shipperStreet\":\"bantian\",\"shipperHouseNumber\":\"A209\",\"shipperAddress\":\"Wuhe South Road\",\"shipperPostcode\":\"419454\",\"shipperMobile\":\"99999\",\"shipperPhone\":\"18883838883\",\"shipperEmail\":\"666666@qq.com\",\"codSum\":\"\",\"codCurrencyCode\":\"\",\"currencyCode\":\"USD\",\"memo\":\"api测试单\",\"returnLabel\":\"1\",\"apiOrderItemList\":[{\"brand\":\"hemers\",\"caseNo\":\"\",\"cname\":\"钱包\",\"ename\":\"wallet\",\"hsCode\":\"4202310090\",\"imageUrl\":\"www.ccc.com\",\"material\":\"Cowhide\",\"price\":2,\"productUrl\":\"\",\"quantity\":1,\"sku\":\"wallet\",\"specifications\":\"\",\"unitCode\":\"PCE\",\"used\":\"\",\"weight\":1.3}],\"apiOrderVolumeList\":[{\"height\":1.2,\"length\":1.3,\"width\":1,\"quantity\":1,\"rweight\":2}]}";
		String respBody = HttpRequest.post(BASE_URL + ORDER_URL).addHeaders(header).body(request).execute().body();
		System.out.println(respBody);
		// {"code":1,"message":"success","data":{"markNo":"CA00210006500","referenceNo":"CNO00001","orderId":"10801","trackingNo":"CA00210006500","labelPath":"http://otms-dev.oss-cn-zhangjiakou.aliyuncs.com/document/order-label/pdf/20210610/CA00210006500.pdf"}}
	}
}
